package com.day21.test3;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Scanner;

public class test {

    public static void main(String[] args) {
        ApplicationContext a=new ClassPathXmlApplicationContext("day21test3.xml");

        crud c=a.getBean("crud",crud.class);

        Scanner scanner=new Scanner(System.in);
        Scanner input1=new Scanner(System.in);
        Scanner input=new Scanner(System.in);

        int flag=0;
        int i=0;
        String name="";


        System.out.println("你可以做的事情有：\n" +
                "1、增加学生信息\n"+
                "2、删除学生信息\n"+
                "3、修改学生信息\n"+
                "4、查询学生信息\n"+
                "5、退出");
        System.out.println("-----------------------------");


        while ((flag=input1.nextInt())!=5){
            switch (flag){
                case 1:
                    System.out.println("请输入学号：");
                    i=scanner.nextInt();
                    System.out.println("请输入名字：");
                    name=input.nextLine();
                    c.insert(i,name);
                    break;
                case 2:
                    System.out.println("请输入要删除学生的学号：");
                    i=scanner.nextInt();
                    c.delete(i);
                    break;
                case 3:
                    System.out.println("请输入要修改名字的学生的学号：");
                    i=scanner.nextInt();
                    System.out.println("请输入要修改的名字：");
                    name=input.nextLine();
                    c.update(i,name);
                    break;
                case 4:
                    System.out.println("请输入要查找的学生的学号：");
                    i=scanner.nextInt();
                    name=c.select(i);
                    System.out.println("要查找的学生的名字为："+name);
                    break;
                default:
                    System.out.println("没有这项功能，少年！");
                    break;

            }
        }

    }
}
